#include "settingsdialog.h"
#include "ui_settingsdialog.h"

SettingsDialog::SettingsDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SettingsDialog)
{
    ui->setupUi(this);
    ui->betterDescriptorsCB->setChecked(GlobalSettings.betterDescriptorsEnabled);
    ui->compressedImagesCB->setChecked(GlobalSettings.resizeEnabled);
    ui->thresholdCB->setCurrentIndex(GlobalSettings.resizeIndex);
    ui->correspondenceSB->setValue(GlobalSettings.minimalCorrespondence);
    ui->resizeSB->setValue(GlobalSettings.resizeTo);



    connect(ui->okButton, SIGNAL(clicked()), this, SLOT(acceptChanges()) );
    connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(declineChanges()) );
}

SettingsDialog::~SettingsDialog()
{
    delete ui;
}

void SettingsDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void SettingsDialog::acceptChanges(){
    GlobalSettings.betterDescriptorsEnabled = ui->betterDescriptorsCB->checkState();
    GlobalSettings.resizeEnabled = ui->compressedImagesCB->checkState();
    GlobalSettings.threshold = ui->thresholdCB->currentText().toInt();
    GlobalSettings.minimalCorrespondence = ui->correspondenceSB->value();
    GlobalSettings.resizeTo = ui->resizeSB->value();
    GlobalSettings.resizeIndex = ui->thresholdCB->currentIndex();
    this->close();
}

void SettingsDialog::declineChanges(){
    this->close();
}
